package com.yanqu.road.server.cmd.activity.xingyoushanshui;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.xingyou.CrossXingYouActivity;
import com.yanqu.road.server.manager.activity.xingyou.CrossXingYouShanShuiMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_XING_YOU_SHAN_SHUI_CONFIRM_EVENT, desc = "二次确认事件")
public class CrossShanShuiConfirmEventCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        XingYouShanShuiProto.ShanShuiConfirmEventReq req = XingYouShanShuiProto.ShanShuiConfirmEventReq.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        CrossXingYouActivity activity = CrossXingYouShanShuiMgr.getActivity(activityId, groupId);
        if(activity != null){
            long indexId = -1;
            if(req.hasIndexId()){
                indexId = req.getIndexId();
            }
            int ret = activity.confirmByCmd(serverId, packet.getPlayerId(), req.getGridId(), indexId, req.getIsDrift());
            if(ret != 0){
                MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.S_XING_YOU_SHAN_SHUI_CONFIRM_EVENT_FROM_CROSS,
                        XingYouShanShuiProto.ShanShuiConfirmEventRsp.newBuilder().setRet(ret)));
            }
        }
    }

    @Override
    public void sendData() {

    }
}
